package com.ecco.client;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;

import com.ecco.persistent.AccObCol;
import com.ecco.persistent.AccObColAgentRemote;
import com.ecco.persistent.Account;
import com.ecco.persistent.AccountAgentRemote;
import com.ecco.persistent.Colour;
import com.ecco.persistent.ColourAgentRemote;
import com.ecco.persistent.Objects;
import com.ecco.persistent.ObjectsAgentRemote;

public class Client {

	public static void main(String[] args) throws ParseException {
		// TODO Auto-generated method stub
		try {
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			
			Context jndiContext = getInitialContext();
			Object ref = jndiContext.lookup("AccountAgentBean/remote");
			AccountAgentRemote dao = (AccountAgentRemote)PortableRemoteObject.narrow(ref, AccountAgentRemote.class);
			
			Object refcol = jndiContext.lookup("ColourAgentBean/remote");
			ColourAgentRemote daocol = (ColourAgentRemote)PortableRemoteObject.narrow(refcol, ColourAgentRemote.class);
			
			Object refob = jndiContext.lookup("ObjectsAgentBean/remote");
			ObjectsAgentRemote daoob = (ObjectsAgentRemote)PortableRemoteObject.narrow(refob, ObjectsAgentRemote.class);
			
			Object refabc = jndiContext.lookup("AccObColAgentBean/remote");
			AccObColAgentRemote daoabc = (AccObColAgentRemote)PortableRemoteObject.narrow(refabc, AccObColAgentRemote.class);
			
			//==try add==
			//--Add Account--
			//dao.addAccount("allen", "Test contact", "0430437908", "allen101479@gmail.com", formatter.parse("1983-09-07"));

			//--Add Object--
			//daoob.addObjects("ob_name");
			
			//--Add Colour--
			//daocol.addColour("col_name", "avail");
			
			//--Add AccObCol--
			//daoabc.addAccObCol(12, 12, 8, "432rerew");
			
			//==try veiw By ID==
			//--Account--
			/*Account account = dao.findAccountById(new Integer(4));
			if (account!=null){
				System.out.println("View Account Info:");
				System.out.println("Account Name: " + account.getAcc_name());
				System.out.println("Contact: " + account.getContact());
				System.out.println("Email: " + account.getEmail());
				System.out.println("Phone: " + account.getPhone());
				System.out.println("Date: " + account.getDate());
				System.out.println("=========================");
				System.out.println("=========================");
				Iterator iteratorAccItem = account.getAocRecords().iterator();
				while (iteratorAccItem.hasNext()){
					System.out.println("View SubAccount Info:");
					AccObCol SubAccount = (AccObCol) iteratorAccItem.next();
					System.out.println("Item: "+ SubAccount.getAoc_id());
					System.out.println("Item: "+ SubAccount.getAccount().getAcc_name());
					System.out.println("Item: "+ SubAccount.getAccount().getContact());
					System.out.println("Item: "+ SubAccount.getObjects().getOb_name());
					System.out.println("Item: "+ SubAccount.getColour().getCol_name());
					System.out.println("Item: "+ SubAccount.getComment());
					System.out.println("=========================");
				}
			} else {
				System.out.println("No thing find out");
			}*/
			
			//--Object--
			/*Objects objects = daoob.findObjectsById(new Integer(2));
			if (objects!=null){
				System.out.println("View Objects Info:");
				System.out.println("Object Name: " + objects.getOb_name());
				System.out.println("=========================");
				System.out.println("=========================");
				Iterator iteratorObItem = objects.getAocRecords().iterator();
				while (iteratorObItem.hasNext()){
					System.out.println("View SubObjects Info:");
					AccObCol SubObjects = (AccObCol) iteratorObItem.next();
					System.out.println("Item: "+ SubObjects.getAoc_id());
					System.out.println("Item: "+ SubObjects.getAccount().getAcc_name());
					System.out.println("Item: "+ SubObjects.getAccount().getContact());
					System.out.println("Item: "+ SubObjects.getObjects().getOb_name());
					System.out.println("Item: "+ SubObjects.getColour().getCol_name());
					System.out.println("Item: "+ SubObjects.getComment());
					System.out.println("=========================");
				}
			} else {
				System.out.println("No thing find out");
			}*/
						
			//--Colour--
			/*Colour colour = daocol.findColourById(new Integer(31));
			if (colour!=null){
				System.out.println("View Colour Info:");
				System.out.println("Colour Name: " + colour.getCol_name());
				System.out.println("Avail: " + colour.getAvail());
				System.out.println("=========================");
				System.out.println("=========================");
				Iterator iteratorColItem = colour.getAocRecords().iterator();
				while (iteratorColItem.hasNext()){
					System.out.println("View SubColour Info:");
					AccObCol SubColour = (AccObCol) iteratorColItem.next();
					System.out.println("Item: "+ SubColour.getAoc_id());
					System.out.println("Item: "+ SubColour.getAccount().getAcc_name());
					System.out.println("Item: "+ SubColour.getAccount().getContact());
					System.out.println("Item: "+ SubColour.getObjects().getOb_name());
					System.out.println("Item: "+ SubColour.getColour().getCol_name());
					System.out.println("Item: "+ SubColour.getComment());
					System.out.println("=========================");
				}
			} else {
				System.out.println("No thing find out");
			}*/
			
			//--AOC--
			/*AccObCol accObCol = daoabc.findAOCById(new Integer(4));
			if (accObCol!=null){
				System.out.println("View AOC Info:");
				System.out.println("Aoc_ID: " + accObCol.getAoc_id());
				System.out.println("Acc_Name: " + accObCol.getAccount().getAcc_name());
				System.out.println("Acc_Contact: " + accObCol.getAccount().getContact());
				System.out.println("Ob_Name: " + accObCol.getObjects().getOb_name());
				System.out.println("Col_Name: " + accObCol.getColour().getCol_name());
				System.out.println("Col_Avail: " + accObCol.getColour().getAvail());
				System.out.println("Comment: " + accObCol.getComment());
				System.out.println("=========================");
			} else {
				System.out.println("No thing find out");
			}*/
			
			
			//==try update==
			//--Account--/
			//dao.updateAccount(new Integer(108), "accName", "contact", "000000", "email", formatter.parse("2007-10-10"));
			
			//--Object--
			//daoob.updateObjects(new Integer(9), "ObjectName Test");
			
			//--Colour--
			//daocol.updateColour(new Integer(308), "accName", "contact");
			
			//--AccObCol--
			//daoabc.updateAccObCol(new Integer(1), new Integer(4), new Integer(4), new Integer(12), "comment");
			
			
			//==try remove==
			//--Account--
			//dao.removeAccountById(new Integer(12));
			
			//--Object--
			//daoob.removeObjectsById(new Integer(12));
			
			//--Colour--
			//daocol.removeColourById(new Integer(12));
			
			//--AOC--
			//daoabc.removeAOCById(new Integer(12));
			
			
			//==try Search==
			//--Account--
			/*List<Account> contentSeaAcc = dao.searchByAccName("%a%");
			Iterator itSeaAcc = contentSeaAcc.iterator();
			while(itSeaAcc.hasNext()) {
				Account thisAccount1 = (Account)itSeaAcc.next();
				System.out.println("View Search Account Info:");
				System.out.println("Search Acc_id: " + thisAccount1.getAcc_id());
				System.out.println("Search Acc_name: " + thisAccount1.getAcc_name());
				System.out.println("Search Contact: " + thisAccount1.getContact());
				System.out.println("=========================");
			}*/
			
			//--Object--	
			/*List<Objects> contentSeaOb = daoob.searchByObName("%r%");
			Iterator itSeaOb = contentSeaOb.iterator();
			while(itSeaOb.hasNext()) {
				Objects thisObjects1 = (Objects)itSeaOb.next();
				System.out.println("View Search Objects Info:");
				System.out.println("Search Ob_id: " + thisObjects1.getOb_id());
				System.out.println("Search Ob_name: " + thisObjects1.getOb_name());
				System.out.println("=========================");
			}*/
			
			//--Colour--	
			/*List<Colour> contentSeaCol = daocol.searchByColName("%G%");
			Iterator itSeaCol = contentSeaCol.iterator();
			while(itSeaCol.hasNext()) {
				Colour thisColour1 = (Colour)itSeaCol.next();
				System.out.println("View Search Colour Info:");
				System.out.println("Search Col_id: " + thisColour1.getCol_id());
				System.out.println("Search Col_name: " + thisColour1.getCol_name());
				System.out.println("Search Avail: " + thisColour1.getAvail());
				System.out.println("=========================");
			}*/
			
			
			//==try View All==
			//--Account--
			/*List<Account> content = dao.findAll();
			Iterator it = content.iterator();
			while(it.hasNext()) {
				Account thisAccount = (Account)it.next();
				System.out.println("View All Account Info:");
				System.out.println("All Acc_id: " + thisAccount.getAcc_id());
				System.out.println("All Acc_name: " + thisAccount.getAcc_name());
				System.out.println("All Contact: " + thisAccount.getContact());
				System.out.println("All Email: " + thisAccount.getEmail());
				System.out.println("All Phone: " + thisAccount.getPhone());
				System.out.println("All Date: " + thisAccount.getDate());
				System.out.println("=========================");
			}*/
			
			//--Object--
			/*List<Objects> contentob = daoob.findAll();
			Iterator itob = contentob.iterator();
			while(itob.hasNext()) {
				Objects thisObjects = (Objects)itob.next();
				System.out.println("View All Objects Info:");
				System.out.println("All Ob_id: " + thisObjects.getOb_id());
				System.out.println("All Ob_name: " + thisObjects.getOb_name());
				System.out.println("=========================");
			}*/

			//--Colour--
			/*List<Colour> contentcol = daocol.findAll();
			Iterator itcol = contentcol.iterator();
			while(itcol.hasNext()) {
				Colour thisColour = (Colour)itcol.next();
				System.out.println("View All Colour Info:");
				System.out.println("All Col_id: " + thisColour.getCol_id());
				System.out.println("All Col_name: " + thisColour.getCol_name());
				System.out.println("All Avail: " + thisColour.getAvail());
				System.out.println("=========================");
			}*/

			//--AOC--
			/*List<AccObCol> contentabc = daoabc.findAll();
			Iterator itabc = contentabc.iterator();
			while(itabc.hasNext()) {
				AccObCol thisAccObCol = (AccObCol)itabc.next();
				System.out.println("View All AOC Info:");
				System.out.println("All Aoc_id: " + thisAccObCol.getAoc_id());
				System.out.println("All Account Name: " + thisAccObCol.getAccount().getAcc_name());
				System.out.println("All Account Contact: " + thisAccObCol.getAccount().getContact());
				System.out.println("All Object Name: " + thisAccObCol.getObjects().getOb_name());
				System.out.println("All Colour Name: " + thisAccObCol.getColour().getCol_name());
				System.out.println("All Avail: " + thisAccObCol.getColour().getAvail());
				System.out.println("All Comment: " + thisAccObCol.getComment());
				System.out.println("=========================");
			}*/
			
			
			//==try View Number of AOC Records By XX_id==
			//--Account--
			Integer aocRecordsByAcc_id = dao.findNumOfAOCRecordsByAcc_id(new Integer(4));
			System.out.println("Number of AOC Records By acc_id: " + aocRecordsByAcc_id);
			System.out.println("=========================");
			
			//--Object--
			Integer aocRecordsByOb_id = daoob.findNumOfAOCRecordsByOb_id(new Integer(6));
			System.out.println("Number of AOC Records By ob_id: " + aocRecordsByOb_id);
			System.out.println("=========================");

			//--Colour--
			Integer aocRecordsByCol_id = daocol.findNumOfAOCRecordsByCol_id(new Integer(57));
			System.out.println("Number of AOC Records By col_id: " + aocRecordsByCol_id);
			System.out.println("=========================");
			
			//==check by XX_name==
			//--Account--
			/*boolean checkAccountByAcc_name = dao.checkByAccName("big w");
			System.out.println("Check Account By acc_name: " + checkAccountByAcc_name);
			System.out.println("=========================");*/
			
			//--Object--
			/*boolean checkObjectByOb_name = daoob.checkByObName("kicker");
			System.out.println("Check Object By ob_name: " + checkObjectByOb_name);
			System.out.println("=========================");*/
			
			//--Colour--
			/*boolean checkColourByCol_name = daocol.checkByColName("other");
			System.out.println("Check Colour By col_name: " + checkColourByCol_name);
			System.out.println("=========================");*/
			
			//==check Acc_Ob_Col==
			/*Account testAccount = new Account(new Integer(12), "accName", "contact", "000000", "email", formatter.parse("2007-10-10"));
			Objects testObjects = new Objects(new Integer(12), "ob_name");
			Colour testColour = new Colour (new Integer(12), "col_name", "avail");
			boolean checkAOCByAcc_Ob_Col = daoabc.checkAOCByAcc_Ob_Col(testAccount, testObjects, testColour);
			System.out.println("Check AOC record By Account Object Colour Classes: " + checkAOCByAcc_Ob_Col);*/

			
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static Context getInitialContext()
		throws NamingException {
		return new InitialContext();
	}

}
